﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Xsl;

namespace Transformer
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Transform failed!, not enough parameters!");
                Console.WriteLine("Transformer data template result");
                return;
            }

            string output_file = "result.output";
            if (args.Length>=3)
            {
                output_file = args[2];
            }

            try
            {
                //
                Console.WriteLine("Transforming ..[{0}] + [{1}] = [{2}]", args[0], args[1], output_file);

                XmlReader _xmlxml = XmlReader.Create(args[0]);
                XmlReader _xmlxsl = XmlReader.Create(args[1]);


                XslCompiledTransform xslct = new XslCompiledTransform();
                xslct.Load(_xmlxsl);

                TextWriter wr = new StreamWriter(output_file);

                xslct.Transform(_xmlxml, null, wr);

                wr.Close();
            }
            catch(Exception e)
            {
                Console.WriteLine("Transforming failed! {0}", e.ToString());
            }
        }
    }
}
